package com.anche.cywebnew.Pojo.exchangeManager.resultData;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * REST接口统一响应体
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {

    /** 默认成功响应码 */
    public static final int SUCCESS_CODE = 1;

    /** 默认成功响应消息 */
    public static final String SUCCESS_MSG = "success";

    /** 默认失败响应码 */
    public static final int FAILED_CODE = 0;

    /** 默认失败响应消息 */
    public static final String FAILED_MSG = "系统异常！";

    private Integer code;

    private String msg;

    private T data;

    public static <T> Result<T> success(T data) {
        return new Result<>(SUCCESS_CODE, SUCCESS_MSG, data);
    }

    public static <T> Result<T> failed() {
        return failed(FAILED_CODE, FAILED_MSG);
    }

    public static <T> Result<T> failed(int code, String msg) {
        return new Result<>(code, msg, null);
    }

}
